<?php
require_once('../../../../conf/config.php.inc');
require_once(SYBMAS_LIB_PATH.'/liblogin.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/layout.php.inc');
require_once(SYBMAS_LIB_PATH.'/libsybmas.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/menu.php.inc');
require_once('../../lib/libtablas.php.inc');
verificar_inicio_sesion();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/sybmasstyle.css">
<script src="<?php echo LAYOUT_URI?>/jquery-1.2.1.min.js"
	type="text/javascript"></script>
<script src="<?php echo LAYOUT_URI?>/menu-collapsed.js"
	type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/style.css" >
<link rel="stylesheet" type="text/css"
	href="<?php echo JAVASCRIPT_URI?>/tabs/tabs.css">
<script src="<?php echo JAVASCRIPT_URI?>/tabs/tabs.js"
	type="text/javascript"></script>
<script src="<?php echo JAVASCRIPT_URI?>/validacionFormularios.js"
	type="text/javascript"></script>

<script type="text/javascript" src="<?php echo JAVASCRIPT_URI?>/commons.js"></script>
<script type="text/javascript" src="index.js"></script>

<title>.:: Sybmas - Crear &iacute;ndice</title>
<!--[if lt IE 8]>
   <style type="text/css">
   li a {display:inline-block;}
   li a {display:block;}
   </style>
   <![endif]-->
</head>
<body>
<script src="<?php echo JAVASCRIPT_URI?>/tooltip/wz_tooltip.js"
	type="text/javascript"></script>
<center>

<div id="container">
<div id="header"><?php generar_header();?></div>
<div id="scene">
<div id="modulos">
<ul id="menu" style="width: 150px;">
<?php generar_menu();?>
</ul>
</div>
<?php
$dbname=false;
foreach($_POST as $key=>$value){
	$$key=$value;
}

?>
<div id="title">Crear &iacute;ndice para tabla: <b><?php echo $tablename;?></b></div>
<div id="main"><?php
$cambio_bd_exitoso=true;
$sybuser_connection=start_default_sybuser_connection();
if($dbname){
	$cambio_bd_exitoso=sybase_select_db($dbname,$sybuser_connection);
}

if($cambio_bd_exitoso){
	?>

<h1>Proporcione los siguientes datos para definir el &iacute;ndice</h1>

<form action="indice2.php" method="post" onsubmit="return verificarFormulario()">
<?php if($dbname){?> 
<input
	type="hidden" name="dbname" value="<?php echo $dbname?>"> 
	<?php }?> 
<div id="tab_panel">
<div id="tab_header">
<ul>
	<li id="selected"><a id="ctl_tabgeneral" href="#" onclick="showTab(this.id,0)">Inf. basica</a></li>
	<li><a id="ctl_tabalmacenamiento" href="#" onclick="showTab(this.id,1)">Almacenamiento</a></li>
	<li><a id="ctl_tabopciones" href="#" onclick="showTab(this.id,2)">Opciones</a></li>	
</ul>
</div>
<div id="tab_content">

<div class="tab_scene" style="display: block">
<?php
$query="SELECT c.name ".
		"FROM syscolumns c ".
		"WHERE c.id=$id ";
$result_columnas=sybase_query($query,$sybuser_connection);
?> 
<table width="80%" border="1" id="index_basic">
	<caption>Informacion b&aacute;sica</caption>
	<tr>
		<th>Nombre del &iacute;ndice</th>
		<td><input type="text" id="idx_name" name="idx_name"
			value="idx_<?php echo $tablename."_".substr(time(),-4)?>"
			maxlength="30" title="Nombre del &iacute;ndice" 
			onkeydown="return onKeyPressPermiteAlfaNumericosNoEspacios(event)"></td>
	</tr>
	<tr>
		<th>&Uacute;nico</th>
		<td><input type="checkbox" name="idx_unique"
			onclick="cambiarIndiceUnico(this.checked)"></td>
	</tr>
	<tr>
		<th>Tipo</th>
		<td>Clustered<input type="radio" name="idx_type"
			onclick="cambiarTipoIndice(this.value)" value="clustered">&nbsp; Non
		clustered<input type="radio" name="idx_type"
			onclick="cambiarTipoIndice(this.value)" value="non clustered"
			checked="checked"></td>
	</tr>
	<tr>
		<th>Propietario</th>
		<td><input type="text" name="tableowner"
			value="<?php echo $tableowner?>" readonly="readonly"></td>
	</tr>
	<tr>
		<th>Nombre de la tabla</th>
		<td><input type="text" name="tablename"
			value="<?php echo $tablename?>" readonly="readonly"></td>
	</tr>
	<tr>
		<th>Columnas</th>
		<td>
		<table>
			<tr id="idx_columnas">
				<td><select multiple="multiple" id="allcolumns" size="5">
				<?php while($data=sybase_fetch_array($result_columnas)){
					?>
					<option value="<?php echo $data['name']?>"><?php echo $data['name']?></option>
					<?php }?>
				</select></td>
				<td><input type="button" value="&gt;&gt;"
					onclick="swapListElements(document.getElementById('allcolumns'),document.getElementById('columns'))" ><br >
				<input type="button" value="&lt;&lt;"
					onclick="swapListElements(document.getElementById('columns'),document.getElementById('allcolumns'))" >
				</td>
				<td><select id="columns" name="columns[]" multiple="multiple" size="5"></select>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
<?php
sybase_free_result($result_columnas);
?>
</div><!-- tab_scene -->


<div class="tab_scene" >
<?php
$query="SELECT s.status,s.name ".
		"FROM syssegments s ".
		"WHERE s.name NOT IN ('system','logsegment')".
		"ORDER BY s.name ASC ";
$result_segmentos=sybase_query($query,$sybuser_connection);
?>
<table width="80%" border="1" id="index_storage">
	<caption>Parametros de almacenamiento</caption>
	<tr>
		<th>Factor de llenado</th>
		<td><input id="fillfactor" type="text" title="fillfactor"
			name="fillfactor" maxlength="3" onkeypress="return onKeyPressPermiteNumeros(event)"></td>
	</tr>
	<tr>
		<th>Filas m&aacute;ximas por p&aacute;gina</th>
		<td><input type="text" title="max_rows_per_page"
			name="max_rows_per_page" maxlength="3" onkeypress="return onKeyPressPermiteNumeros(event)" ></td>
	</tr>
	<tr>
		<th>Espacio reservado vac&iacute;o por p&aacute;gina</th>
		<td><input type="text" title="reservspacegap" name="reservspacegap"
			maxlength="3" onkeypress="return onKeyPressPermiteNumeros(event)"></td>
	</tr>
	<tr>
		<th>Segmento</th>
		<td><select name="segment">
		<?php while($data=sybase_fetch_array($result_segmentos)){
			?>
			<option value="<?php echo $data['name']?>"
			<?php echo $data['status']==1?' selected ':''?>><?php echo $data['name']?>			
			</option>
			<?php }?>
		</select></td>
	</tr>
</table>
</div><!-- tab_scene -->


<div class="tab_scene" >
<?php
sybase_free_result($result_segmentos);
?>

<table id="index_options" width="80%" border="1">
	<caption>Opciones</caption>
	<tr id="index_options_nouniqueclustered" style="display: none">
		<th>Filas duplicadas</th>
		<td>
			Ignorar<input title="ignore_dup_row" type="radio"
			value="ignore_dup_row" > Permitir<input title="permitir"
			type="radio" name="allow_dup_row" >		
		</td>
	</tr>
	<tr id="ignore_dup_row" style="display: none">
		<th>Filas duplicadas</th>
		<td>
			Ignorar<input title="ignore_dup_row"
			type="checkbox" name="ignore_dup_row" >
		</td>
	</tr>
	<tr id="ignore_dup_key" style="display: none">
		<th>Llaves duplicadas</th>
		<td>Ignorar <input type="checkbox" title="ignore_dup_key"
			name="ignore_dup_key"></td>
	</tr>
</table>
</div><!-- tab_scene -->

	
</div><!-- tab_content -->
</div><!-- tab_panel -->

<table>
	<tr>
		<td colspan="2"><input type="submit" value="Crear indice"> <input
			type="button" value="Cancelar" onclick="history.back()" ></td>
	</tr>
</table>

</form>
<?php
}//if($cambio_bd_exitoso)

//Cerrando conexiones a la base de datos
sybase_close($sybuser_connection);
?>


</div>
<!-- main --></div>
<!-- scene --> <?php generar_footer();?></div>
</center>
</body>
</html>
